package com.yuma.function4;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

public class FunctionDemo {
    public static void main(String[] args) {
        // 传入第一个泛型，返回值是第二个泛型
        Function<Float,Integer> function = new Function<Float, Integer>() {
            @Override
            public Integer apply(Float fl) {
                return Math.round(fl);
            }
        };
        System.out.println(function.apply(1.5f));

        Function<String,Integer> function2 = str -> Integer.parseInt(str);
        System.out.println(function2.apply("123"));

        List<String> list = new ArrayList<>();
        list.add("hello");
        list.add("kitty");
        list.add("yuma");
        list.add("function");
        list.stream().map(str -> str.toUpperCase()).forEach(str -> System.out.println(str));
        list.stream().map(str -> str.length()).forEach(str -> System.out.println(str));
        list.stream().map(str -> str.substring(0,2)).forEach(str -> System.out.println(str));
        list.stream().map(str -> str.contains("hello")).forEach(str -> System.out.println(str));
    }
}
